package mhwi.cards.taidao;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DamageAction;
import com.megacrit.cardcrawl.actions.common.DamageAllEnemiesAction;
import com.megacrit.cardcrawl.actions.common.ReducePowerAction;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.powers.IntangiblePower;
import com.sun.org.apache.xpath.internal.operations.Mod;
import mhwi.actions.ApplyKaiRenPowerAction;
import mhwi.cards.BaDaoCard;
import mhwi.cards.HunterTemplateCard;
import mhwi.helper.ModHelper;
import mhwi.powers.*;

import static mhwi.constants.ResourcesConstant.EXTENSION_PNG;
import static mhwi.constants.ResourcesConstant.PATH_IMG_CARDS_TAIDAO;
import static mhwi.enums.ModEnums.PlayerColorEnum.CARD_COLOR_HUNTER_TAIDAO;

public class TiCaoKaiRenCard extends HunterTemplateCard {
    private static final String CLASS_NAME = TiCaoKaiRenCard.class.getSimpleName();
    public static final String ID = ModHelper.makeId(CLASS_NAME);
    private static final CardStrings CARD_STRINGS = CardCrawlGame.languagePack.getCardStrings(ID);
    private static final String NAME = CARD_STRINGS.NAME;
    private static final String IMG_PATH = ModHelper.makeFileName(PATH_IMG_CARDS_TAIDAO, CLASS_NAME, EXTENSION_PNG);
    private static final String DESCRIPTION = CARD_STRINGS.DESCRIPTION;
    private static final CardColor COLOR = CARD_COLOR_HUNTER_TAIDAO;

    private static final int COST = 2;
    private static final CardType TYPE = CardType.ATTACK;
    private static final CardRarity RARITY = CardRarity.COMMON;
    private static final CardTarget TARGET = CardTarget.ALL_ENEMY;

    public TiCaoKaiRenCard() {
        super(ID, NAME, IMG_PATH, COST, DESCRIPTION, TYPE, COLOR, RARITY, TARGET);
        this.baseDamage = 8;
        this.baseMagicNumber = 4;

        this.tags.add(CardTags.STRIKE);
    }

    // 升级卡牌
    @Override
    public void upgrade() {
        if (!upgraded) {
            upgradeName();
            upgradeDamage(2);
            upgradeMagicNumber(-1);
            this.rawDescription = CARD_STRINGS.UPGRADE_DESCRIPTION;
            initializeDescription();
        }
    }

    // 使用卡牌
    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        AbstractDungeon.actionManager.addToTop(new ReducePowerAction(p, p, LianQiPower.POWER_ID, this.baseMagicNumber));
        if (!ModHelper.hasPowers(BaDaoPower.POWER_ID)) {
            AbstractDungeon.actionManager.addToTop(new ApplyPowerAction(p, p, new BaDaoPower(p), 1));
        }
        AbstractDungeon.actionManager.addToTop(new DamageAllEnemiesAction(p, this.damage,  DamageInfo.DamageType.NORMAL, AbstractGameAction.AttackEffect.SLASH_DIAGONAL));
        AbstractDungeon.actionManager.addToTop(new ApplyKaiRenPowerAction(p));
    }

    @Override
    public boolean canUse(AbstractPlayer p, AbstractMonster m) {
        return super.canUse(p, m) && ModHelper.getPowersAmount(p, LianQiPower.POWER_ID) >= this.baseMagicNumber;
    }
}